﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NNTH.Data
{
    public partial class BangDiem : System.ComponentModel.IDataErrorInfo
    {
        public string MonHoc
        {
            get
            {
                return this.KeHoachHT.MonHoc.TenMH;
            }
        }
        public double? Diem
        {
            get
            {
                if (Diem2>Diem1)
                {
                    return Diem2;
                }
                if (this.Diem1!=null)
                {
                    return this.Diem1;
                }
                else
                {
                    if (this.Diem2 != null)
                    {
                        return this.Diem2;
                    }
                }
                return null;
            }
        }
        public string Error
        {
            get
            {
                if (this.EntityState == System.Data.EntityState.Added || this.EntityState == System.Data.EntityState.Modified)
                {
                    StringBuilder sb = new StringBuilder();

                    if (!String.IsNullOrWhiteSpace(this["MaHV"]))
                        sb.AppendLine(this["MaHV"]);

                    if (!String.IsNullOrWhiteSpace(this["Diem1"]))
                        sb.AppendLine(this["Diem1"]);

                    if (!String.IsNullOrWhiteSpace(this["Diem2"]))
                        sb.AppendLine(this["Diem2"]);

                    string errors = sb.ToString();
                    return !String.IsNullOrEmpty(errors) ? errors : String.Empty;
                }
                else
                {
                    return String.Empty;
                }
            }
        }

        public string this[string columnName]
        {
            get
            {
                if (this.EntityState == System.Data.EntityState.Added || this.EntityState == System.Data.EntityState.Modified)
                {
                    switch (columnName)
                    {
                        case "MaHV":
                            return this.HocVien==null ? "Chưa có học viên!" : String.Empty;
                        case "Diem1":
                            if (this.Diem1!=null)
                            {
                                return ((this.Diem1 < 0) ||(this.Diem1>10)) ? "Điểm thi 2 chưa hợp lệ!" : String.Empty;
                            }
                            return String.Empty;
                        case "Diem2":
                            if (this.Diem2!=null)
                            {
                                return ((this.Diem2 < 0) ||(this.Diem2>10)) ? "Điểm thi 2 chưa hợp lệ!" : String.Empty;
                            }
                            return String.Empty;
  
                        default:
                            return String.Empty;
                    }
                }
                else
                {
                    return String.Empty;
                }
            }
        }
    }
}
